package com.javaex.book.service.impl;

import java.math.BigDecimal;
import java.util.List;

import com.javaex.book.dao.BookDao;
import com.javaex.book.dao.impl.BookDaoImpl;
import com.javaex.book.pojo.Book;
import com.javaex.book.service.BookService;
import com.javaex.book.utils.Pagination;
import com.javaex.book.utils.ReturnResult;

public class BookServiceImpl implements BookService {

	private BookDao bookDao = new BookDaoImpl();
	
	@Override
	public ReturnResult addBook(Book book) {
		ReturnResult result = new ReturnResult();
		int rows = bookDao.addBook(book);
		if (rows == 0) {
			return result.fail("添加失败");
		}
		return result.success();
	}

	@Override
	public Integer deleteBookById(Integer id) {
		return bookDao.deleteBookById(id);
	}

	@Override
	public Integer updateBook(Book book) {
		return bookDao.updateBook(book);
	}

	@Override
	public Book queryBookById(Integer id) {
		return bookDao.queryBookById(id);
	}

	@Override
	public List<Book> queryBookList(Pagination pagination, BigDecimal minPrice, BigDecimal maxPrice) {
		return bookDao.queryBookList(pagination, minPrice, maxPrice);
	}

	@Override
	public Integer countBooks(BigDecimal minPrice, BigDecimal maxPrice) {
		return bookDao.countBooks(minPrice, maxPrice);
	}

}
